package com.ruoyi.web.controller.wb;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.wb.domain.WbFireServiceUnit;
import com.ruoyi.wb.dto.WbFireServiceUnitDto;
import com.ruoyi.wb.service.IWbFireServiceUnitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 消防单位Controller
 * 
 * @author ruoyi
 * @date 2025-01-06
 */
@RestController
@RequestMapping("/wb/fireServiceUnit")
public class WbFireServiceUnitController extends BaseController
{
    @Autowired
    private IWbFireServiceUnitService wbFireServiceUnitService;

    /**
     * 查询消防单位列表
     */
    @GetMapping("/list")
    public TableDataInfo list(WbFireServiceUnit wbFireServiceUnit)
    {
        startPage();
        List<WbFireServiceUnit> list = wbFireServiceUnitService.selectWbFireServiceUnitList(wbFireServiceUnit);
        return getDataTable(list);
    }

    /**
     * 导出消防单位列表
     */
    @Log(title = "消防单位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WbFireServiceUnit wbFireServiceUnit)
    {
        List<WbFireServiceUnit> list = wbFireServiceUnitService.selectWbFireServiceUnitList(wbFireServiceUnit);
        ExcelUtil<WbFireServiceUnit> util = new ExcelUtil<WbFireServiceUnit>(WbFireServiceUnit.class);
        util.exportExcel(response, list, "消防单位数据");
    }

    /**
     * 获取消防单位详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wbFireServiceUnitService.selectWbFireServiceUnitById(id));
    }

    /**
     * 新增消防单位
     */
    @Log(title = "消防单位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WbFireServiceUnitDto wbFireServiceUnitDto)
    {
        return toAjax(wbFireServiceUnitService.insertWbFireServiceUnit(wbFireServiceUnitDto));
    }

    /**
     * 修改消防单位
     */
    @Log(title = "消防单位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WbFireServiceUnit wbFireServiceUnit)
    {
        return toAjax(wbFireServiceUnitService.updateWbFireServiceUnit(wbFireServiceUnit));
    }

    /**
     * 删除消防单位
     */
    @Log(title = "消防单位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wbFireServiceUnitService.deleteWbFireServiceUnitByIds(ids));
    }
}
